package com.gzhu.knowledgeAdmin.controller;

import com.gzhu.knowledgeAdmin.common.config.GoFastDfsConfig;
import com.gzhu.knowledgeAdmin.common.constant.ExcelConstants;
import com.gzhu.knowledgeAdmin.common.result.R;
import com.gzhu.knowledgeAdmin.common.utils.GoFastDfsUtil;
import com.gzhu.knowledgeAdmin.entity.AVideo;
import com.gzhu.knowledgeAdmin.service.AVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.List;

@RestController
public class AVideoController {
    @Autowired
    private AVideoService aVideoService;

    @Autowired
    private GoFastDfsUtil goFastDfsUtil;

    //因为之前拦截器 设置了不拦截了audio/* 故改名
    @PostMapping("/audiof/upload")
    public R<String> AUploadFile(@RequestParam("file") MultipartFile file) throws IOException, URISyntaxException {
        String url=aVideoService.uploadFile(file);

       return R.ok(url);
    }
    @PostMapping("/audio/select")
    public R<List<AVideo>> SelectFile(@RequestBody AVideo aVideo){
        System.out.println(aVideo);
        List<AVideo> aVideoList=aVideoService.select(aVideo);
        return R.ok(aVideoList);
    }

    @PostMapping("/video/upload")
    public R<String> VUploadFile(@RequestParam("file") MultipartFile file) throws IOException, URISyntaxException {
        String url=aVideoService.VUpload(file);

        return R.ok(url);
    }
    @PostMapping("/AVideo/export")
    public void downloadTemplate(@RequestBody AVideo aVideo, HttpServletResponse response) throws IOException, URISyntaxException {
        System.out.println("音视频导出结果"+aVideo);
        aVideoService.exportAVideo(aVideo,response);
    }
    @PostMapping("/scan/file")
    public R<String> FileScan() throws IOException, URISyntaxException {

        return R.ok(aVideoService.filescan());
    }

}
